package main

import (
	_ "embed"
	"log"
	"weboffice-go-sdk/examples/internal/demo"
	"weboffice-go-sdk/weboffice"
)

type TestProvider struct {
	demo *demo.Provider
}

func (t *TestProvider) GetFile(ctx weboffice.Context, fileID string) (*weboffice.GetFileReply, error) {
	return t.demo.GetFile(ctx, fileID)
}

func (t *TestProvider) RenameFile(ctx weboffice.Context, fileID string, args *weboffice.RenameFileArgs) error {
	return t.demo.RenameFile(ctx, fileID, args)
}

func (t *TestProvider) UpdateFile(ctx weboffice.Context, fileID string, args *weboffice.UpdateFile1PhaseArgs) (*weboffice.GetFileReply, error) {
	return t.demo.UpdateFile(ctx, fileID, args)
}

func (t *TestProvider) GetFileDownload(ctx weboffice.Context, fileID string) (*weboffice.GetFileDownloadReply, error) {
	return t.demo.GetFileDownload(ctx, fileID)
}

func (t *TestProvider) GetUsers(ctx weboffice.Context, userIDs []string) ([]*weboffice.User, error) {
	return t.demo.GetUsers(ctx, userIDs)
}

func (t *TestProvider) GetFileWatermark(_ weboffice.Context, _ string) (*weboffice.GetWatermarkReply, error) {
	return &weboffice.GetWatermarkReply{
		Type:       1,
		Value:      "weboffice-go-sdk",
		FillStyle:  "rgba(192,192,192,0.6)",
		Font:       "bold 20px Serif",
		Rotate:     0.5,
		Horizontal: 50,
		Vertical:   50,
	}, nil
}

func (t *TestProvider) GetFilePermission(ctx weboffice.Context, fileID string) (*weboffice.GetFilePermissionReply, error) {
	return t.demo.GetFilePermission(ctx, fileID)
}

func (t *TestProvider) GetFileVersions(ctx weboffice.Context, fileID string, offset, limit int) ([]*weboffice.GetFileReply, error) {
	return t.demo.GetFileVersions(ctx, fileID, offset, limit)
}

func (t *TestProvider) GetFileVersion(ctx weboffice.Context, fileID string, version int32) (*weboffice.GetFileReply, error) {
	return t.demo.GetFileVersion(ctx, fileID, version)
}

func (t *TestProvider) GetFileVersionDownload(ctx weboffice.Context, fileID string, version int32) (*weboffice.GetFileDownloadReply, error) {
	return t.demo.GetFileVersionDownload(ctx, fileID, version)
}

func main() {
	const prefix = "/weboffice-go-sdk/"

	provider := &TestProvider{
		demo: demo.NewProvider(),
	}
	server := weboffice.NewServer(weboffice.Config{
		BaseProvider:      provider,
		UserProvider:      provider,
		WatermarkProvider: provider,
		EditProvider:      provider,
		VersionProvider:   provider,
		Logger:            weboffice.DefaultLogger(),
		Prefix:            prefix,
	})
	server.Router().GET(prefix+"download", provider.demo.DownloadFile)

	if err := server.Run(":8080"); err != nil {
		log.Fatal(err)
	}
}
